import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:honeypotflutter/public/views/public_appBar.dart';
import 'package:honeypotflutter/publicBussine/bussine_colors.dart';
import 'package:honeypotflutter/publicBussine/bussine_font.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_button.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_card.dart';
import 'package:honeypotflutter/publicBussine/view/bussine_item.dart';
import 'logic.dart';

class AutonymTextPage extends StatefulWidget {
  const AutonymTextPage({Key? key}) : super(key: key);

  @override
  State<AutonymTextPage> createState() => _AutonymTextPageState();
}

class _AutonymTextPageState extends State<AutonymTextPage> {
  final AutonymTextLogic logic = Get.put(AutonymTextLogic());
  final FocusNode _nameNode = FocusNode();
  final FocusNode _cardNode = FocusNode();
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: HLAppBar(navigationTitle: "实名认证"),
      body: MGCard(
        margin: EdgeInsets.all(12),
        nodeList: [_nameNode, _cardNode],
        children: [
          MGItems(
            leadTitle: "姓名",
            showBottomSplit: true,
            trailingWidget: _createTextField(
              hintText: "请输入您的姓名",
              controller: logic.nameController,
              node: _nameNode,
            ),
          ),
          MGItems(
            leadTitle: "身份证号",
            trailingWidget: _createTextField(
              hintText: "请输入您的身份证号",
              controller: logic.cardController,
              node: _cardNode,
            ),
          )
        ],
      ),
      bottomNavigationBar: Obx(() => MGButton(
            title: "下一步",
            enable: logic.enable.value,
            padding: EdgeInsets.only(left: 20, right: 20, bottom: 35, top: 20),
            buttonAction: logic.nextButtonAction,
          )),
    );
  }

  /*
  * 创建输入框
  * */
  Widget _createTextField({String? hintText, TextEditingController? controller, FocusNode? node}) {
    TextField field = TextField(
      controller: controller,
      textAlign: TextAlign.end,
      focusNode: node,
      decoration: InputDecoration(
        hintText: hintText,
        hintStyle: TextStyle(
          fontSize: MGFont.textFont2,
          color: MGColors.text3Color,
        ),
        enabledBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
        focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: Colors.transparent)),
      ),
    );
    return Expanded(
        child: Container(
      height: 30,
      child: field,
    ));
  }

  @override
  void dispose() {
    Get.delete<AutonymTextLogic>();
    super.dispose();
  }
}
